package com.example.controller;

import com.example.entity.StudentScore;
import com.example.service.StudentScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/scores")
public class StudentScoreController {
    @Autowired
    private StudentScoreService service;

    @PostMapping("/submit")
    public ResponseEntity<?> submitScore(@RequestBody StudentScore score) {
        try {
            StudentScore savedScore = service.saveScore(score);
            return ResponseEntity.ok(savedScore);
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(e.getMessage());
        }
    }

    // 获取指定学校和专业的学生排名
    @GetMapping("/rankings")
    public ResponseEntity<List<StudentScore>> getRankings(@RequestParam String school, @RequestParam String major) {
        List<StudentScore> scores = service.getScoresBySchoolAndMajor(school, major);
        return ResponseEntity.ok(scores);
    }
}

